#include <func.h>
void cleanfunc(void *p)
{
    free((char*)p);
    printf("I am cleanfunc!\n");
    printf("Free success!\n");
}
void *thfunc(void *p)
{
    printf("I am subthread!\n");
    char *buf=(char*)malloc(10);
    pthread_cleanup_push(cleanfunc,buf);
    read(STDIN_FILENO,buf,sizeof(buf));
    pthread_cleanup_pop(1);
}
int main(int argc,char *argv[])
{
    int ret;
    pthread_t pthid;
    ret=pthread_create(&pthid,NULL,thfunc,NULL);
    THREAD_ERROR_CHECK(ret,"pthread_create");
    printf("I am main thread\n");
    sleep(1);
    pthread_cancel(pthid);
    THREAD_ERROR_CHECK(ret,"pthread_cancel");
    pthread_join(pthid,NULL);
    THREAD_ERROR_CHECK(ret,"pthread_join");
    return 0;
}

